package com.lfk.demo.Ability;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;

import com.lfk.demo.ResourceTable;
import com.lfk.justwetools.Component.CircleGraph.CircleGraph;
import com.lfk.justwetools.Component.Clock.Clock;
import com.lfk.justwetools.Component.LineProgress.LineProgress;
import ohos.utils.zson.ZSONArray;
import ohos.utils.zson.ZSONException;
import ohos.utils.zson.ZSONObject;

public class ViewDemoAbility extends Ability {

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setPattern(ResourceTable.Pattern_base);
        setUIContent(ResourceTable.Layout_ability_view_demo);

        initCircleGraph();

        initLineProgress();

        initClock();
    }

    private void initCircleGraph() {
        ZSONArray jsonArray = new ZSONArray();
        ZSONObject object1 = new ZSONObject();
        try {
            object1.put("name", "1");
            object1.put("sweep", 200);
            object1.put("color", 0xFFFEDD74);
        } catch (ZSONException e) {
            e.printStackTrace();
        }
        ZSONObject object2 = new ZSONObject();
        try {
            object2.put("name", "2");
            object2.put("sweep", 20);
            object2.put("color", 0xFF82D8EF);
        } catch (ZSONException e) {
            e.printStackTrace();
        }
        jsonArray.add(object1);
        jsonArray.add(object2);
        CircleGraph graph = (CircleGraph) findComponentById(ResourceTable.Id_circle_graph);
        graph.setText("搞基");
        graph.setJson(jsonArray.toString());
    }

    private void initLineProgress() {
        final LineProgress lineProgress = (LineProgress) findComponentById(ResourceTable.Id_linepro);
        findComponentById(ResourceTable.Id_button).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component v) {
                lineProgress.setProgressing(lineProgress.getProgressing() + 10);
            }
        });
    }

    private void initClock() {
        ((Clock) findComponentById(ResourceTable.Id_clock)).
                setColor(getColor(ResourceTable.Color_colorPrimary));
    }
}
